'use strict';

/**
 * Created by twer on 15/3/2.
 */
angular.module('microblog').controller('MicroBlogEditCtrl', [
    '$scope',
    '$routeParams',
    'PathSuffixConstant',
    'MicroBlogEditService',
    function ($scope, $routeParams, PathSuffixConstant, MicroBlogEditService) {
        var author = {identity: $routeParams.userId};

        $scope.microblog = {};

        $scope.add = function () {
            if (!$scope.microblog.content) {
                alert("请填写微博内容！");
                return;
            }

            $scope.microblog.author = author;
            MicroBlogEditService.save($scope.microblog, function (response) {
                $scope.$emit('MicroBlogCreatedEvent', {
                    _id: response._id,
                    content: $scope.microblog.content
                });
                $scope.microblog.content = '';
            });
        };



    }]);
